package com.example.day02.mefrag;

import android.app.AlertDialog;
import android.content.Intent;
import android.graphics.Bitmap;
import android.os.Bundle;

import androidx.fragment.app.Fragment;

import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.WindowManager;
import android.widget.TextView;

import com.example.day02.Custom.DLRoundImageView;
import com.example.day02.R;
import com.example.day02.utils.AssetsUtils;


/**
 * A simple {@link Fragment} subclass.
 */
public class MeFragment extends Fragment implements View.OnClickListener {
    private static final String TAG = "MeFragment";
    TextView aboutTv;
    TextView introduce;
    TextView update;
    TextView problem;
    TextView starTv;
    String name;
    String show_logo_name;
    DLRoundImageView imageView;
    public MeFragment() {
        // Required empty public constructor
    }

    @Override
    public void onResume() {
        super.onResume();
        starTv.setText(name);
        String filename="xzcontentlogo/"+show_logo_name+".png";;
        Bitmap bm = AssetsUtils.getBitmapByAssets(getContext(), filename);
        imageView.setImageBitmap(bm);
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        View view=inflater.inflate(R.layout.fragment_me, container, false);
        Bundle bundle = getArguments();
        name = bundle.getString("name");
        show_logo_name = bundle.getString("show_logo_name");
        Log.d(TAG, "show_logo_name: "+show_logo_name);
        Log.d(TAG, "name: "+name);
        initView(view);
        return view;
    }

    private void initView(View view) {
        aboutTv=view.findViewById(R.id.mefrag_tv_about);
        aboutTv.setOnClickListener(this);
        introduce=view.findViewById(R.id.mefrag_tv_introduce);
        introduce.setOnClickListener(this);
        update=view.findViewById(R.id.mefrag_tv_update);
        update.setOnClickListener(this);
        problem=view.findViewById(R.id.mefrag_tv_problem);
        problem.setOnClickListener(this);
        imageView=view.findViewById(R.id.mefrag_iv);
        imageView.setOnClickListener(this);
        String filename="xzcontentlogo/"+show_logo_name+".png";;
        Bitmap bm = AssetsUtils.getBitmapByAssets(getContext(), filename);
        imageView.setImageBitmap(bm);
        starTv=view.findViewById(R.id.chose_star_name);
        starTv.setText(name);
    }

    @Override
    public void onClick(View v) {
        Intent intent = new Intent();
        switch (v.getId()) {
            case R.id.mefrag_tv_about:
                intent.setClass(getContext(),AboutActivity.class);
                startActivity(intent);
                break;
            case R.id.mefrag_tv_introduce:
                intent.setClass(getContext(),IntroduceActivity.class);
                startActivity(intent);
                break;
            case R.id.mefrag_tv_update:
                intent.setClass(getContext(),UpdateActivity.class);
                startActivity(intent);
                break;
            case R.id.mefrag_tv_problem:
                intent.setClass(getContext(),ProblemActivity.class);
                startActivity(intent);
                break;
            case R.id.mefrag_iv:
                 intent.setClass(getContext(),LogoActivity.class);
                 startActivity(intent);

                break;
        }

    }
}
